package com.zdy.im.chat;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author 作者 : zdy
 * @CreateDate 创建时间: 2021-02-30
 * @WeeK 星期: 星期四
 * @Version 版本: v1.0.0
 * <pre>
 *
 *  @Description (说明):  消息类型枚举参数
 *
 **/

public  enum ChatMessageEnum {

    // 数据操作错误定义
    MESSAGE_DEFAULT(0,0, "未知消息，或异常消息"),

    MESSAGE_STATUS_PING(1,0, "心跳"),
    MESSAGE_STATUS_READY(2,1, "链接就绪"),

    MESSAGE_TYPE_FRIEND(11,1, "单聊"),
    MESSAGE_TYPE_GROUP(12, 2,"群聊"),

    MESSAGE_TYPE_CONTENT(21,1, "文本消息,包括表情"),
    MESSAGE_TYPE_IMAGE(22, 2,"图片消息"),
    MESSAGE_TYPE_VIDEO(23, 3,"视频消息"),
    MESSAGE_TYPE_CARD(24, 4,"名片"),
    MESSAGE_TYPE_CONTENT_IMAGE(25, 5,"文本和图片"),
    MESSAGE_TYPE_CONTENT_VIDEO(26, 6,"文本和视频"),
    MESSAGE_TYPE_MAGE_VIDEO(27, 7,"图片和视频"),
    MESSAGE_TYPE_SHARE_GROUP(28, 8,"分享群"),
    MESSAGE_TYPE_SHARE_FILE(29, 9,"文件类型"),
    MESSAGE_TYPE_SHARE_OTHER(30, 10,"其它类型"),

    MESSAGE_STATUS_JOIN_FRIEND(41,11, "申请加好友"),
    MESSAGE_STATUS_JOIN_ROOM(42,12, "申请加入群"),
    MESSAGE_STATUS_AGREE_FRIEND(43,13, "添加好友公告"),

    MESSAGE_STATUS_READ(31,0, "未读"),
    MESSAGE_STATUS_UNREAD(32,1, "已读"),
    MESSAGE_STATUS_CANCEL(33,2, "撤销"),
    MESSAGE_STATUS_DELETE(34,3, "删除"),




    ;
    /**
     * 消息协议的与cmd平级的type类型的传的值
     * ChatMessageInfo 类对象中type的值
     */
    private final int code;

    /**
     * 消息协议的type类型的传的值
     * ChatMessageInfo 类对象中ChatMessageBody对象中messageType的值
     */
    private  final int dbValue;

    /**
     * 消息协议描述
     */
    private final String desc;

    ChatMessageEnum(int code, int dbValue, String desc) {
        this.code = code;
        this.dbValue = dbValue;
        this.desc = desc;
    }

    private static final Map<Integer, ChatMessageEnum> enumMap = new HashMap<>();

    static {
        ChatMessageEnum[] list = ChatMessageEnum.values();
        if(list != null && list.length >0){
            for(ChatMessageEnum chat : list){
                enumMap.put(chat.code, chat);
            }
        }
    }

    public static ChatMessageEnum getEnum(int code){
        ChatMessageEnum cme =  enumMap.get(code);
        if(null == cme){
            cme = ChatMessageEnum.MESSAGE_DEFAULT;
        }return cme;
    }

    public int getCode() {
        return code;
    }

    public int getDbValue() {
        return dbValue;
    }

    public String getDesc() {
        return desc;
    }
}
